package com.xiao.provider.controller;


import com.xiao.provider.service.UserService;
import com.xiao.provider.vo.reqvo.UserReqVo;
import com.xiao.provider.vo.resvo.UserResVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @Description 用户控制器
 * @Auther: 笑笑是一个码农
 * @Date: 16:09 2020/12/22
 */
@RestController
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 添加用户接口
     * @param userReqVo
     */
    @PostMapping(value = "/v1/provider/user")
    public void addUser(@RequestBody @Validated UserReqVo userReqVo){
        userService.insert(userReqVo);
    }

    /**
     * 查询用户接口
     * @param id
     * @return
     */
    @GetMapping(value = "/v1/provider/user/{id}")
    public UserResVo getUser(@PathVariable("id") Long id){
        return userService.selectById(id);
    }

    /**
     * 修改用户接口
     * @param id
     * @param userReqVo
     */
    @PutMapping(value = "/v1/provider/user/{id}")
    public void updateUser(@PathVariable("id") Long id, @RequestBody @Validated UserReqVo userReqVo){
        userService.update(id, userReqVo);
    }

    /**
     * 删除用户接口
     * @param id
     */
    @DeleteMapping(value = "/v1/provider/user/{id}")
    public void deleteUser(@PathVariable("id") Long id){
        userService.delete(id);
    }
}
